/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GroupOfTreatmentPanel.java
 *
 * Created on 08.07.2009, 1:10:09
 */

package ru.vsu.cs.piit.vokod.view.panels;

import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import ru.vsu.cs.piit.vokod.model.GroupOfTreatment;

/**
 *
 * @author Галчонок
 */
public class GroupOfTreatmentPanel extends javax.swing.JPanel {
    GroupOfTreatment groupOfTreatment;

    /** Creates new form GroupOfTreatmentPanel */
    public GroupOfTreatmentPanel() {
        this(new GroupOfTreatment());
    }

    public GroupOfTreatmentPanel(GroupOfTreatment g) {
        initComponents();
        this.groupOfTreatment = g;
        SetValues();
        AddActions();
        this.setSize(this.getPreferredSize());
    }

    void AddActions(){
        tfCode.addFocusListener(new FocusListener() {

            public void focusGained(FocusEvent e) {}

            public void focusLost(FocusEvent e) {
                groupOfTreatment.setCode(tfCode.getText());
            }
        });

        tfName.addFocusListener(new FocusListener() {

            public void focusGained(FocusEvent e) {}

            public void focusLost(FocusEvent e) {
                groupOfTreatment.setName(tfName.getText());
            }
        });
    }

    void SetValues(){
        tfCode.setText(groupOfTreatment.getCode());
        tfName.setText(groupOfTreatment.getName());
    }

    public GroupOfTreatment getGroupOfTreatment() {
        return groupOfTreatment;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        tfName = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        tfCode = new javax.swing.JTextField();

        jLabel1.setText("Название группы");

        jLabel2.setText("Код");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(tfCode, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 216, Short.MAX_VALUE)
                    .addComponent(tfName, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 216, Short.MAX_VALUE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(4, 4, 4)
                .addComponent(tfName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(4, 4, 4)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tfCode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JTextField tfCode;
    private javax.swing.JTextField tfName;
    // End of variables declaration//GEN-END:variables

}
